package com.spvs.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spvs.common.log.annotation.Log;
import com.spvs.common.log.enums.BusinessType;
import com.spvs.common.security.annotation.RequiresPermissions;
import com.spvs.system.domain.FileComment;
import com.spvs.system.service.IFileCommentService;
import com.spvs.common.core.web.controller.BaseController;
import com.spvs.common.core.web.domain.AjaxResult;
import com.spvs.common.core.utils.poi.ExcelUtil;
import com.spvs.common.core.web.page.TableDataInfo;

/**
 * 文件留言Controller
 *
 * @author supervision
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/comment")
public class FileCommentController extends BaseController
{
    @Autowired
    private IFileCommentService fileCommentService;

    /**
     * 查询文件留言列表
     */
    @RequiresPermissions("system:comment:list")
    @GetMapping("/list")
    public TableDataInfo list(FileComment fileComment)
    {
        startPage();
        List<FileComment> list = fileCommentService.selectFileCommentList(fileComment);
        return getDataTable(list);
    }

    /**
     * 导出文件留言列表
     */
    @RequiresPermissions("system:comment:export")
    @Log(title = "文件留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileComment fileComment)
    {
        List<FileComment> list = fileCommentService.selectFileCommentList(fileComment);
        ExcelUtil<FileComment> util = new ExcelUtil<FileComment>(FileComment.class);
        util.exportExcel(response, list, "文件留言数据");
    }

    /**
     * 获取文件留言详细信息
     */
    @RequiresPermissions("system:comment:query")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(fileCommentService.selectFileCommentByCommentId(commentId));
    }

    /**
     * 新增文件留言
     */
    @RequiresPermissions("system:comment:add")
    @Log(title = "文件留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileComment fileComment)
    {
        return toAjax(fileCommentService.insertFileComment(fileComment));
    }

    /**
     * 修改文件留言
     */
    @RequiresPermissions("system:comment:edit")
    @Log(title = "文件留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileComment fileComment)
    {
        return toAjax(fileCommentService.updateFileComment(fileComment));
    }

    /**
     * 删除文件留言
     */
    @RequiresPermissions("system:comment:remove")
    @Log(title = "文件留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(fileCommentService.deleteFileCommentByCommentIds(commentIds));
    }
}
